<?php
    header('content-type:text/html;charset=utf-8');

    $conn = new mysqli('localhost', 'root', 'root', 'sy2004');

    if ($conn->connect_error) {
        die('数据库连接错误' . $conn->connect_error);
    }

    // echo '连接成功';

    // 定义字段
    $pagenum = $_GET['pagenum'];
    $pagesize = $_GET['pagesize'];
    // $pagenum = 1;
    // $pagesize = 12;

    $start = ($pagenum - 1) * $pagesize;

    $sql = "SELECT * FROM `jinxiang` LIMIT $start, $pagesize";

    $res = $conn->query($sql);

    $arr = Array();



    while($row = mysqli_fetch_assoc($res)) {
        array_push($arr, $row);
    }

    $n = 0;

    $sql2 = "SELECT * FROM `jinxiang`";

    $res2 = $conn->query($sql2);
    
    while ($row2 = mysqli_fetch_assoc($res2)) {
        $n++;
    }

    echo json_encode(Array(
        'total' => $n,
        'code' => 0,
        'msg' => '请求成功',
        'data' => $arr
    ));
?>